Teruhiro Komaki's Diary (Archive)

タグ:AWS Lambda(2)

author
Teruhiro Komaki komaki.dev
2024年 04月 03日 水曜日
16時00分

AWS Lambdaの`event`を確認

API GatewayのGETメソッドでAWS Lambda関数を統合している場合に、eventで受け取る値を確認しました。

以下のような#AWS Lambdaを実行しました。

export const handler = async (event) => {

  console.log(JSON.stringify(event));

  const response = {
    statusCode: 200,
    body: JSON.stringify('Hello from Lambda!'),
  };
  return response;
};

API Gatewayからテスト

実行結果

API Gatewayからテスト
API Gatewayからテスト
{
  "resource": "/",
  "path": "/",
  "httpMethod": "GET",
  "headers": {
    "header2": "value2",
    "header1": "value1"
  },
  "multiValueHeaders": {
    "header2": [
      "value2"
    ],
    "header1": [
      "value1"
    ]
  },
  "queryStringParameters": {
    "param1": "value1",
    "param2": "value2"
  },
  "multiValueQueryStringParameters": {
    "param1": [
      "value1"
    ],
    "param2": [
      "value2"
    ]
  },
  "pathParameters": null,
  "stageVariables": null,
  "requestContext": {
    "resourceId": "zbkgq2150i",
    "resourcePath": "/",
    "httpMethod": "GET",
    "extendedRequestId": "Vo6HgFCYoAMFchg=",
    "requestTime": "03/Apr/2024:07:50:07 +0000",
    "path": "/",
    "accountId": "123456789123",
    "protocol": "HTTP/1.1",
    "stage": "test-invoke-stage",
    "domainPrefix": "testPrefix",
    "requestTimeEpoch": 1712130607770,
    "requestId": "05f4bb29-e600-4968-aeb8-12e062caa698",
    "identity": {
      "cognitoIdentityPoolId": null,
      "cognitoIdentityId": null,
      "apiKey": "test-invoke-api-key",
      "principalOrgId": null,
      "cognitoAuthenticationType": null,
      "userArn": "arn:aws:iam::123456789123:user/xxx-xxx",
      "apiKeyId": "test-invoke-api-key-id",
      "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36",
      "accountId": "123456789123",
      "caller": "AIDAQGIBVCFDQW6HXLIGK",
      "sourceIp": "test-invoke-source-ip",
      "accessKey": "ASIAQGIBVCFDRFRRWRO5",
      "cognitoAuthenticationProvider": null,
      "user": "AIDAQGIBVCFDQW6HXLIGK"
    },
    "domainName": "testPrefix.testDomainName",
    "apiId": "vjs9lsoti0"
  },
  "body": null,
  "isBase64Encoded": false
}

自分用のメモでした。

author
Teruhiro Komaki komaki.dev
2024年 04月 03日 水曜日
14時00分

AWS Lambdaの`process.env`を確認

以下のような#AWS Lambdaを実行しました。

export const handler = async (event) => {

  console.log(JSON.stringify(process.env));

  const response = {
    statusCode: 200,
    body: JSON.stringify('Hello from Lambda!'),
  };
  return response;
};

実行結果

{
  "AWS_LAMBDA_FUNCTION_VERSION": "$LATEST",
  "AWS_EXECUTION_ENV": "AWS_Lambda_nodejs20.x",
  "AWS_DEFAULT_REGION": "us-east-1",
  "AWS_LAMBDA_LOG_STREAM_NAME": "2024/04/03/[$LATEST]066a5738b9ba4cc09d6e0c0a70f7e466",
  "AWS_REGION": "us-east-1",
  "PWD": "/var/task",
  "_HANDLER": "index.handler",
  "TZ": ":UTC",
  "LAMBDA_TASK_ROOT": "/var/task",
  "LANG": "en_US.UTF-8",
  "AWS_SECRET_ACCESS_KEY": "DZQ9rrfVi0oz9Nn4/iyZr81r4P3U9jH6K9bVt75q",
  "AWS_LAMBDA_LOG_GROUP_NAME": "/aws/lambda/tmp-20240403_143239",
  "AWS_LAMBDA_RUNTIME_API": "127.0.0.1:9001",
  "AWS_LAMBDA_FUNCTION_MEMORY_SIZE": "128",
  "LAMBDA_RUNTIME_DIR": "/var/runtime",
  "_AWS_XRAY_DAEMON_ADDRESS": "169.254.79.129",
  "AWS_XRAY_DAEMON_ADDRESS": "169.254.79.129:2000",
  "SHLVL": "0",
  "AWS_ACCESS_KEY_ID": "ASIAQGIBVCFD7EZXTHMZ",
  "LD_LIBRARY_PATH": "/var/lang/lib:/lib64:/usr/lib64:/var/runtime:/var/runtime/lib:/var/task:/var/task/lib:/opt/lib",
  "NODE_PATH": "/opt/nodejs/node20/node_modules:/opt/nodejs/node_modules:/var/runtime/node_modules:/var/runtime:/var/task",
  "AWS_LAMBDA_FUNCTION_NAME": "tmp-20240403_143239",
  "PATH": "/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin",
  "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand",
  "AWS_SESSION_TOKEN": "IQoJb3JpZ2luX2VjEEYaCXVzLWVhc3QtMSJHMEUCIHaOAVEBa8742bDc8NqIX1ecHNJi3rTajSttzvVk4XvaAiEAvFoY1nR+GX3DuMgtRYEZ0QRyLbgG8lRCo/pvMbz2WMYq+gIIbxADGgwwMTM0MjUyNTA2MzEiDFYK7zAtz02PVUTQ5yrXAjp2DzTSnmE7mljD2vvM92SKKAVkGz4UtWfCsCbLaGIwPGsf/WHPTcMV/vJRF1VbOiMlEtbYOh4FVfn7Vhr/+GoiV9lIsOf7aILN7R/bvHVSTjZ0TdoraYLr6b5unKImPWMwwvTnbxQ4HyNitcc/DzfyGxbbtRsyAru8OUZJAc4knxhX7+M7yOe4Ula8678RoOD6RTQ4yyeH6zA6E/OrgReMJBG+hfthSRWeP1UACesfjiUOZMwvvSLUZHwuESgpbsvq8sBsv+UQ+Lc0tc8l9g6+bOijtQgDwITEerHmxQCf5qRTEirQbitkFxmMlOjyKGtZ8THbztV4/gc9XOyhXOrw0LpX6MywCr+xHhC3PD7ValT882pNRQ8I+5twQpfjVzVZybHlvU7VlL9B96DsmQfbzxEKz883MNb9yjqrNX9tJ5k0ofCfKfVPQ1QAR47phy5wAvDXqMYw3NSzsAY6ngGoft73ap2zAoTMCEvIxGP6eLyZQdcBhzKrSzFURSU9o3oZ5qTrP6huGuNKC+2P49rvsqp1Djqu3WtniNSXpBOFPWz4FnleByQOz6+x64SuXqKKtqTG2n1KIBZ9Yu5uUHSC8eaK4YyGY00AqRex/kpA5yN7wSGghvAOyPXlUo7pyZQ7uWNHiybypN9+zpnjY2Gl+aSCLPwEZThzUV4n9g==",
  "AWS_XRAY_CONTEXT_MISSING": "LOG_ERROR",
  "_AWS_XRAY_DAEMON_PORT": "2000",
  "_X_AMZN_TRACE_ID": "Root=1-660cea5c-31b5dc97257d60084e97c6d4;Parent=1dd3fa1526589d56;Sampled=0;Lineage=bf0b63a4:0"
}

自分用のメモでした。